// pages/Access/index.js

let app = getApp();
const HttpAjax = getApp().getHttpData;
import Toast from '../../../components/dist/toast/toast';


Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    key: {},
    imgclass:'opendoor1',
    
  },
  cahngesearch(event) {
    console.log(event.detail);
    this.setData({
      searchval: event.detail
    })
  },
  ClosePOP() {
    this.setData({
      show: !this.data.show
    })
  },
  /**
   * 开门
   */
  openPOP(e) {
    console.log(e.target.dataset.did);
    let did = e.target.dataset.did
    let cid = e.target.dataset.cid;
    Toast.loading({
      mask: true,
      duration: 0,
      message: '正在开门...'
    });
    HttpAjax(app.globalData.url + '/AsyncDoor/OpenDoor', { DoorID: did, CustomerID: cid }, 'post', app.globalData.headerCookie)
      .then(ress => {
        Toast.clear();
        let res = ress.data;
        console.log(res);
        if (res.result == 1) {
          Toast.success('开门成功');
        }
        if (res.result == -2) {
          Toast.fail('无此门权限');
        }
        if (res.result == -3) {
          Toast.fail('门已离线，开门失败');
        }
      }).catch(err => {
        Toast.clear()
      })
  },
  toaddcurm() {
    wx.navigateTo({
      url: '../bindCard/addcard/index',
    })
  },
  showId(){
    this.setData({
      imgclass:'opendoor2'
    })
  },
  unshowId(e){
    
    this.setData({
      imgclass: 'opendoor1'
    })
    if (!this.data.key.Online){
      Toast('门已离线！')
      return
    }
    this.openPOP(e)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let key=JSON.parse(options.key);
    // key.Online=0;
    this.setData({
      key:key
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log(123)
    this.setData({
      loading:'数据加载中'
    })
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.getData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(456);
    let self = this;
    // setTimeout(()=>{
    //   self.setData({
    //     ALLdata: self.data.ALLdata+10
    //   })
    // },500)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})